Interrupt 21h Function 6Ch
Opens or
creates a file having the given name and attributes.
mov ah, 6Ch ; Extended Open/Create
mov bx, ModeAndFlags ; see below
mov cx, Attributes ; see below
mov dx, Action ; action to take
mov si, seg Filename ; see below
mov ds, si
mov si, offset Filename
int 21h
jc error
mov [Handle], ax ; file handle
mov [ActionTaken], cx ; action taken to open file
Parameters
ModeAndFlags
Combination
of access mode, sharing mode, and open flags. This parameter can be one value
each from the access and sharing modes and any combination of open flags:
Access
mode |
Meaning |
|
OPEN_ACCESS_READONLY
(0000h) |
|
|
|
Opens the
file for reading only. |
|
OPEN_ACCESS_WRITEONLY
(0001h) |
|
|
|
Opens the
file for writing only. |
|
OPEN_ACCESS_READWRITE
(0002h) |
|
|
|
Opens the
file for reading and writing. |
|
0003h |
|
|
|
Reserved;
do not use. |
|
OPEN_ACCESS_RO_NOMODLASTACCESS
(0004h) |
|
|
|
Opens the
file for reading only without modifying the file s last access date. |
|
Sharing
mode |
Meaning |
|
OPEN_SHARE_COMPATIBLE
(0000h) |
|
|
|
Opens the
file with compatibility mode, allowing any process on a given computer to
open the file any number of times. |
|
OPEN_SHARE_DENYREADWRITE
(0010h) |
|
|
|
Opens the
file and denies both read and write access to other processes. |
|
OPEN_SHARE_DENYWRITE
(0020h) |
|
|
|
Opens the
file and denies write access to other processes. |
|
OPEN_SHARE_DENYREAD
(0030h) |
|
|
|
Opens the
file and denies read access to other processes. |
|
OPEN_SHARE_DENYNONE
(0040h) |
|
|
|
Opens the
file without denying read or write access to other processes, but no process
may open the file with compatibility mode. |
|
Open
flags |
Meaning |
|
OPEN_FLAGS_NOINHERIT
(0080h) |
|
|
|
If this
flag is set, a child process created with Load and Execute Program (Interrupt
21h Function 4B00h) does not inherit the file handle. If the handle is needed
by the child process, the parent process must pass the handle value to the
child process. If this flag is not set, child processes inherit the file
handle. |
|
OPEN_FLAGS_NOCRITERR
(2000h) |
|
|
|
If a
critical error occurs while MS-DOS is opening this file, Critical-Error
Handler (Interrupt 24h) is not called. Instead, MS-DOS simply returns an
error value to the program. |
|
OPEN_FLAGS_COMMIT
(4000h) |
|
|
|
After each
write operation, MS-DOS commits the file (flushes the contents of the cache
buffer to disk). |
|
Attributes
Attributes
for files that are created or truncated. This parameter may be a combination of
these values:
_A_NORMAL
(0000h) |
|
|
|
The file
can be read from or written to. This value is valid only if used alone. |
|
_A_RDONLY
(0001h) |
|
|
|
The file
can be read from, but not written to. |
|
_A_HIDDEN
(0002h) |
|
|
|
The file is
hidden and does not appear in an ordinary directory listing. |
|
_A_SYSTEM
(0004h) |
|
|
|
The file is
part of the operating system or is used exclusively by it. |
|
_A_VOLID
(0008h) |
|
|
|
The name
specified by Filename is used as the volume label for the current
medium. |
|
_A_ARCH
(0020h) |
|
|
|
The file is
an archive file. Applications use this value to mark files for backup or
removal. |
|
Action
Action to
take it the file exists or does not exist. This parameter can be a combination
of these values:
FILE_CREATE
(0010h) |
Creates a
new file if it does not already exist or fails if the file already exists. |
FILE_OPEN
(0001h) |
Opens the
file. The function fails if the file does not exist. |
FILE_TRUNCATE
(0002h) |
Opens the
file and truncates it to zero length (replaces the existing file). The
function fails if the file does not exist. |
The only
valid combinations are FILE_CREATE combined with FILE_OPEN or FILE_CREATE
combined with FILE_TRUNCATE.
Filename
Address of a
null-terminated string specifying the name of the file to be opened or created.
The name must be in the standard MS-DOS 8.3 filename format. The string must be
a valid path for the volume associated with the given drive.
Return Value
Clears the
carry flag, copies the file handle to the AX register, and sets CX to one of
the following values if successful:
ACTION_OPENED
(0001h) |
ACTION_CREATED_OPENED
(0002h) |
ACTION_REPLACED_OPENED
(0003h) |
Otherwise,
this function sets the carry flag and sets the AX register to one of the
following error values:
ERROR_INVALID_FUNCTION
(0001h) |
ERROR_FILE_NOT_FOUND
(0002h) |
ERROR_PATH_NOT_FOUND
(0003h) |
ERROR_TOO_MANY_OPEN_FILES
(0004h) |
ERROR_ACCESS_DENIED
(0005h) |
Remarks
This function
does not support long filenames. If the specified name is too long, this
function truncates the name to the standard 8.3 format following the same
naming scheme that the system uses when creating an alias for a long filename.
A file on a
remote directory that is, a
directory on the network cannot be
opened, unless appropriate permissions for the directory exist.